import { getToken, setToken, removeToken } from '@/plugins/utils/auth'
const userTypes = {
  '0': 'superAdmin',
  '1': 'commonAdmin'
}
const state = {
  token: getToken(),
  userName: '',
  userType: 0, // 0是超级管理员，1是普通管理员
  roles: []
}

const mutations = {
  setUserType: (state, payload) => {
    state.userType = payload.userType

    // state.roles = [userTypes[state.userType]]
    let token = `${state.userName}_${state.userType}`
    state.token = token
    setToken(token)
  },
  setRoles: (state, payload) => {
    state.roles = [userTypes[state.userType]]
  },
  removeUserInfo: (state, payload) => {
    state.token = ''
    state.roles = []
    removeToken()
  },
  resetToken: (state) => {
    state.token = ''
    state.roles = []
    removeToken()
  }
}

const actions = {
}
export default {
  state,
  mutations,
  actions
}